<!--
 * @Description: 视点查看功能
 * @Autor: 韩怡婷
 * @Date: 2021-12-28 10:05:52
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2022-12-30 13:53:37
-->
<template>
  <div>
    <left-group
      :viewList="list"
      @updateList="updateList"
      @selectGroupId="nowSelectGroupId = $event"
      @isCanEdit ="isCanEdit = $event"
      @getOtherGroup = "getOtherGroupList"
      @resetRightListAllChecked="resetRightListAllChecked"
    ></left-group>
     <right-list ref="rightListRef" :list="list" :isCanEdit = "isCanEdit" :getOtherGroup = "getOtherGroup"  @getNewList="getNewList" :nowSelectGroupId="nowSelectGroupId"></right-list>
  </div>
</template>
<script>
import AgPopup from "@/views/components/precut/AgPopup.vue";
import imageDataApi from "@/views/js/api/imageDataApi";
import LeftGroup from "./viewPointGroup/LeftGroup.vue";
import RightList from './viewPointList/RightList.vue';
export default {
  name: "viewPointManage",
  components: {
    AgPopup,
    "left-group": LeftGroup,
    'right-list': RightList,
  },
  data() {
    return {
      list: [], //视点列表
      nowSelectGroupId: undefined, //当前选中的组id
      visibleViewPoint: true, //视点查看暂时以弹框形式展示
      isCanEdit:false,
      getOtherGroup:[],
    };
  },
  created() {},
  mounted() {
    // this.updateList();
  },
  computed: {},
  watch: {
    nowSelectGroupId(nv){
      this.$refs.rightListRef.resetAllChecked();
      this.updateList(nv);
    }
  },
  methods: {
    resetRightListAllChecked(){
      this.$refs.rightListRef.resetAllChecked();
    },
    getOtherGroupList(obj){
      this.getOtherGroup = obj;
    },
    getNewList(obj){
      this.updateList(obj);
    },
    /**
     * @lastUpdateBy : 韩怡婷
     * @description: 从小到大排序
     */    
    up(x,y){
      return x.sort - y.sort;
    },
    /**
     * @lastUpdateBy : 韩怡婷
     * @description: 更新视点列表
     */
    updateList(id) {
      if (!id){
        this.list = [];
        return;
      }
      let param = {
        dirId:id,
        page:1,
        rows:1000,
      };
      imageDataApi.selectAuthPageByDirId(param).then((response) => {
        this.list = response.content.list.sort(this.up).filter((item) => {
            //两个版本用同一个接口，数据源略有不同，用tag区分
            try {
              item.json = JSON.parse(item.imageStoreInformation);
            } catch (error) {
              item.json = item.imageStoreInformation;
              console.dir(error);
            }
            item.checked = false;
            return item;
        });
      });
    },
  },
};
</script>

<style scoped>
.viewPoint-popbox {
  position: absolute;
  width: 372px;
  z-index: 1;
  right: 24px;
  top: 80px;
}
.viewpoint-container {
  max-height: 540px;
}

* {
  box-sizing: border-box;
} 
.container{
  width: 350px;
  padding: 10px;
}
</style>
